﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterSGA.Master" AutoEventWireup="true" CodeBehind="BrowseSupporter.aspx.cs" Inherits="SGA.Supporters.BrowseSupporter" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <ajaxToolkit:ToolkitScriptManager ID="ScriptManager" runat="server"></ajaxToolkit:ToolkitScriptManager>
    <asp:UpdatePanel ID="UpdateLoading" runat="server">
        <ContentTemplate>
            <div class="container-fluid">
                <div class="row">

                    <%--botoões barra lateral--%>
                    <div class="col-md-1 sidebar">
                        <ul class="nav nav-pills nav-stacked">
                            <li class="active">
                                <asp:Button ID="SearchButton" runat="server" Text="Pesquisa" OnClick="SearchButton_Click" CssClass="btn btn-default navbar-btn" Width="100" />
                            </li>
                            <li>
                                <asp:Button ID="ClearButton" runat="server" Text="Cancelar" OnClick="ClearButton_Click" CssClass="btn btn-default navbar-btn" CausesValidation="False" Width="100" />
                            </li>
                        </ul>
                        <%--Start: Update progress control--%>
                        <asp:UpdateProgress ID="UpdateProgressLoading" runat="server" AssociatedUpdatePanelID="UpdateLoading">
                            <ProgressTemplate>
                                <img alt="Progresso" src="/Images/progress.gif" />
                                Processar...
                            </ProgressTemplate>
                        </asp:UpdateProgress>
                        <%--End: Update progress control--%>
                    </div>

                    <div class="col-md-11 main">
                        <h3>Pesquisa de Aderentes
                        </h3>

                        <%--controles para introdução de dados de pesquisa--%>
                        <div class="form-group">
                            <div class="row">
                                <div class="col-md-2">
                                    <asp:TextBox ID="IdSupportersTextBox" CssClass="form-control" placeholder="Número" runat="server" />
                                </div>
                                <div class="col-md-4">
                                    <asp:CompareValidator runat="server" Operator="DataTypeCheck" Type="Integer" ControlToValidate="IdSupportersTextBox" ErrorMessage="Erro: Obrigatório números inteiros"></asp:CompareValidator>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="row">
                                <div class="col-md-6">
                                    <asp:TextBox ID="NameTextBox" CssClass="form-control" placeholder="Nome" runat="server" />
                                </div>

                                <div class="col-md-4">
                                    <div class="input-group">
                                        <span class="input-group-addon">Status associado</span>
                                        <asp:DropDownList ID="IdDonationSituationsDropDownList" runat="server" AppendDataBoundItems="True" CssClass="form-control" DataSourceID="EDSDonationSituations" DataTextField="Designation" DataValueField="Id">
                                            <asp:ListItem Value=""></asp:ListItem>
                                        </asp:DropDownList>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="row">
                                <div class="col-md-6">
                                    <asp:TextBox ID="AddressTextBox" CssClass="form-control" placeholder="Endereço" runat="server" />
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="row">
                                <div class="col-md-2">
                                    <asp:TextBox ID="PostalCodeLocalTextBox" CssClass="form-control" placeholder="Cód. postal (4)" runat="server" Columns="10" />
                                </div>
                                <div class="col-md-2">
                                    <asp:TextBox ID="PostalCodeStreetTextBox" CssClass="form-control" placeholder="Cód. postal (3)" runat="server" Columns="3" />
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="input-group">
                                        <span class="input-group-addon">Escolha um tipo de contacto</span>
                                        <asp:DropDownList ID="ContactTypesDropDownList" runat="server" DataSourceID="EDSContactTypes" CssClass="form-control" DataTextField="Designation" DataValueField="Id" AppendDataBoundItems="True" AutoPostBack="true" OnSelectedIndexChanged="ContactTypesDropDownList_SelectedIndexChanged">
                                            <asp:ListItem Value=""></asp:ListItem>
                                        </asp:DropDownList>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <asp:TextBox ID="ContactTextBox" runat="server" placeholder="Contato" CssClass="form-control" Enabled="False" />
                                </div>
                            </div>
                        </div>

                        <%--resultado da pesquisa--%>
                        <div class="form-group">
                            <div class="row">
                                <div class="col-md-5">
                                    <%--Start: Query extender control--%>
                                    <asp:QueryExtender ID="QESupporters" runat="server" TargetControlID="EDSSupporter">
                                        <asp:SearchExpression DataFields="Designation" SearchType="StartsWith">
                                            <asp:ControlParameter ControlID="NameTextBox" />
                                        </asp:SearchExpression>

                                        <asp:SearchExpression DataFields="PostalCodeLocal" SearchType="StartsWith">
                                            <asp:ControlParameter ControlID="PostalCodeLocalTextBox" />
                                        </asp:SearchExpression>

                                        <asp:SearchExpression DataFields="PostalCodeStreet" SearchType="StartsWith">
                                            <asp:ControlParameter ControlID="PostalCodeStreetTextBox" />
                                        </asp:SearchExpression>

                                        <asp:SearchExpression DataFields="Address" SearchType="StartsWith">
                                            <asp:ControlParameter ControlID="AddressTextBox" />
                                        </asp:SearchExpression>

                                        <asp:CustomExpression OnQuerying="FilterByContact_Querying"></asp:CustomExpression>

                                        <asp:RangeExpression DataField="Id" MaxType="Inclusive" MinType="Inclusive">
                                            <asp:ControlParameter ControlID="IdSupportersTextBox" />
                                            <asp:ControlParameter ControlID="IdSupportersTextBox" />
                                        </asp:RangeExpression>
                                    </asp:QueryExtender>
                                    <%--End: Query extender control--%>

                                    <asp:ListView runat="server" ID="LVSupporters" DataKeyNames="Id" OnItemCommand="LVSupporters_ItemCommand">
                                        <ItemTemplate>
                                            <tr runat="server" id="PopupRow">
                                                <td><%#Eval("Id")%></td>
                                                <td><%#Eval("Designation")%></td>
                                                <td><%#Eval("PostalCodeLocal")%></td>
                                            </tr>
                                            <ajaxToolkit:HoverMenuExtender ID="HoverMenu" runat="server"
                                                PopupControlID="PopupMenu"
                                                PopupPosition="Right"
                                                TargetControlID="PopupRow"
                                                PopDelay="50" HoverDelay="10" OffsetX="-10" OffsetY="-40" />

                                            <asp:Panel ID="PopupMenu" runat="server" Width="500" Style="display: none">
                                                <div class="panel panel-default">
                                                    <div class="panel-heading">Dados do aderente</div>
                                                    <div class="panel-body">
                                                        <asp:LinkButton ID="LinkButtonSelect" runat="server" Text="Editar dados" CommandName="Select" CommandArgument='<%#Eval("Id") %>'></asp:LinkButton>
                                                        <ul>
                                                            <li>
                                                                <asp:Label runat="server" Text='<%# "Morada: " + Eval("Address")%>'></asp:Label>
                                                                <asp:Label runat="server" Text='<%# "," + Eval("PostalCodeLocal") + "-" + Eval("PostalCodeStreet") %>'></asp:Label>
                                                            </li>
                                                            <li>
                                                                <%# "Data obtenção:" + Eval("ObtainDate","{0:dd/MM/yyyy}")%>
                                                            </li>
                                                            <li>
                                                                <%# "Status aderente:" + Eval("Situations.Designation")%>
                                                            </li>
                                                            <li>
                                                                <asp:Label runat="server" Text='<%# "Status associado: " + Eval("Associates.DonationSituations.Designation")%>'></asp:Label>
                                                            </li>
                                                        </ul>
                                                    </div>
                                                </div>
                                            </asp:Panel>
                                        </ItemTemplate>
                                        <LayoutTemplate>
                                            <table runat="server" class="table table-hover table-bordered">
                                                <tr>
                                                    <th>
                                                        <asp:LinkButton runat="server" Text="Num." CommandName="Sort" CommandArgument="Id"></asp:LinkButton></th>
                                                    <th>
                                                        <asp:LinkButton runat="server" Text="Nome" CommandName="Sort" CommandArgument="Designation"></asp:LinkButton></th>
                                                    <th>
                                                        <asp:LinkButton runat="server" Text="CP" CommandName="Sort" CommandArgument="PostalCodeLocal"></asp:LinkButton></th>
                                                </tr>
                                                <tr id="itemPlaceholder" runat="server">
                                                </tr>
                                            </table>
                                            <asp:DataPager runat="server" ID="DataPager" PageSize="5">
                                                <Fields>
                                                    <asp:NumericPagerField ButtonCount="10" PreviousPageText="Anterior" NextPageText="Seguinte" />
                                                </Fields>
                                            </asp:DataPager>
                                        </LayoutTemplate>
                                    </asp:ListView>

                                    <!-- Start: Data source -->
                                    <asp:EntityDataSource runat="server" ID="EDSSupporter" DefaultContainerName="MailingEntities" ConnectionString="name=MailingEntities" EntitySetName="Supporters" AutoGenerateWhereClause="False" AutoGenerateOrderByClause="False" Include="Treatments, Associates.DonationSituations, Situations"></asp:EntityDataSource>
                                    <asp:EntityDataSource ID="EDSTreatments" runat="server" DefaultContainerName="MailingEntities" ConnectionString="name=MailingEntities" EntitySetName="Treatments" EntityTypeFilter="Treatments" OrderBy="" AutoPage="False" AutoSort="False" AutoGenerateOrderByClause="True">
                                        <OrderByParameters>
                                            <asp:Parameter DefaultValue="Designation" Name="newparameter" />
                                        </OrderByParameters>
                                    </asp:EntityDataSource>

                                    <asp:EntityDataSource ID="EDSContactTypes" runat="server" DefaultContainerName="MailingEntities" ConnectionString="name=MailingEntities" EntitySetName="ContactTypes" EntityTypeFilter="ContactTypes" OrderBy="" AutoPage="False" AutoSort="False" AutoGenerateOrderByClause="True" Select="">
                                        <OrderByParameters>
                                            <asp:Parameter DefaultValue="Designation" Name="newparameter" />
                                        </OrderByParameters>
                                    </asp:EntityDataSource>

                                    <asp:EntityDataSource ID="EDSSituations" runat="server" DefaultContainerName="MailingEntities" ConnectionString="name=MailingEntities" EntitySetName="Situations" EntityTypeFilter="Situations" OrderBy="" AutoPage="False" AutoSort="False" AutoGenerateOrderByClause="True" Select="">
                                        <OrderByParameters>
                                            <asp:Parameter DefaultValue="Designation" Name="newparameter" />
                                        </OrderByParameters>
                                    </asp:EntityDataSource>

                                    <asp:EntityDataSource ID="EDSSendThankLetters" runat="server" DefaultContainerName="MailingEntities" ConnectionString="name=MailingEntities" EntitySetName="SendThankLetters" EntityTypeFilter="SendThankLetters" OrderBy="" AutoPage="False" AutoSort="False" AutoGenerateOrderByClause="True" Select="">
                                        <OrderByParameters>
                                            <asp:Parameter DefaultValue="Designation" Name="newparameter" />
                                        </OrderByParameters>
                                    </asp:EntityDataSource>

                                    <asp:EntityDataSource ID="EDSProfessions" runat="server" DefaultContainerName="MailingEntities" ConnectionString="name=MailingEntities" EntitySetName="Professions" EntityTypeFilter="Professions" OrderBy="" AutoPage="False" AutoSort="False" AutoGenerateOrderByClause="True" Select="">
                                        <OrderByParameters>
                                            <asp:Parameter DefaultValue="Designation" Name="newparameter" />
                                        </OrderByParameters>
                                    </asp:EntityDataSource>

                                    <asp:EntityDataSource ID="EDSAddressTypes" runat="server" DefaultContainerName="MailingEntities" ConnectionString="name=MailingEntities" EntitySetName="AddressTypes" EntityTypeFilter="AddressTypes" OrderBy="" AutoPage="False" AutoSort="False" AutoGenerateOrderByClause="True" Select="">
                                        <OrderByParameters>
                                            <asp:Parameter DefaultValue="Designation" Name="newparameter" />
                                        </OrderByParameters>
                                    </asp:EntityDataSource>

                                    <asp:EntityDataSource ID="EDSCountries" runat="server" DefaultContainerName="MailingEntities" ConnectionString="name=MailingEntities" EntitySetName="Countries" EntityTypeFilter="Countries" OrderBy="" AutoPage="False" AutoSort="False" AutoGenerateOrderByClause="True" Select="">
                                        <OrderByParameters>
                                            <asp:Parameter DefaultValue="Designation" Name="newparameter" />
                                        </OrderByParameters>
                                    </asp:EntityDataSource>

                                    <asp:EntityDataSource ID="EDSDonationSituations" runat="server" DefaultContainerName="MailingEntities" ConnectionString="name=MailingEntities" EntitySetName="DonationSituations" EntityTypeFilter="DonationSituations" OrderBy="" AutoPage="False" AutoSort="False" AutoGenerateOrderByClause="True" Select="">
                                        <OrderByParameters>
                                            <asp:Parameter DefaultValue="Designation" Name="newparameter" />
                                        </OrderByParameters>
                                    </asp:EntityDataSource>
                                    <!-- End: Data source -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
